from datetime import datetime, timedelta
import random


__all__ = [
    "randdatetime"
]

def randdatetime(start_dt: datetime, end_dt: datetime) -> datetime:
    """
    Generate a random date in [star_date, end_date), accurate to the second.
    
    Args:
        start_dt (datetime.datetime): The start datetime
        end_dt (datetime.datetime): The end datetime
    
    Returns:
        datetime.datetime: The random datetime
    """
    if start_dt.microsecond != 0:
        start_dt = start_dt.replace(microsecond=0) + timedelta(seconds=1)
    if end_dt.microsecond != 0:
        end_dt = end_dt.replace(microsecond=0) + timedelta(seconds=1)
    if start_dt >= end_dt:
        raise ValueError("start_dt must be less than end_dt")
    delta = end_dt - start_dt
    total_seconds = int(delta.total_seconds())
    random_second = random.randrange(total_seconds)
    return start_dt + timedelta(seconds=random_second)


randint = random.randint